Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7990481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:01:25+00:00 2026-06-04T13:01:25+00:00

I am facing a critical problem. I have a page that has two parts.

  • 0

I am facing a critical problem. I have a page that has two parts. On the first part of the page, the html is rendered through an ajax request. And on the second page, the html is rendered on page load. Fist part of the page is handled separately having different pagination script. Pagination is also handled by sending ajax request to the same url.

I have a problem with part one. The script that generates the html for part one is also generating a lot of javascript tags and html using javascript. Now what I am doing when inserting a new script tag in that html is like this:

var script   = document.createElement("script");
script.type  = "text/javascript";
script.text  = "window.twttr = (function (d,s,id) {var t, js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;js.src=\"//platform.twitter.com/widgets.js\"; fjs.parentNode.insertBefore(js, fjs);return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });}(document, \"script\", \"twitter-wjs\"));(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return;js = d.createElement(s); js.id = id; js.src = \"//connect.facebook.net/en_GB/all.js#xfbml=1\"; fjs.parentNode.insertBefore(js, fjs);}(document, \"script\", \"facebook-jssdk\"));var script_generated=1";               // use this for inline script
document.body.appendChild(script);

It is in fact Twitter and Facebook connect statements to show a Facebook like button and a Twitter button on each item of the first part of the page. When the page loads for the first time, the script tag is generated successfully. But when I click on pagination, it sends a new ajax request to have html for a new page, it also generates the same script tag again. So on the second page my Twitter button and Facebook like buttons are not being shown.

I though it was due to double connecting statements of Facebook and Twitter. Then I generate a variable and set some value while generating that script tag. And on each request I check whether that variable exists or not. If it exists I don’t generate that particular script tag like this:

if(typeof script_generated === "undefined") {
  var script   = document.createElement("script");
  script.type  = "text/javascript";
  script.text  = "window.twttr = (function (d,s,id) {var t, js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;js.src=\"//platform.twitter.com/widgets.js\"; fjs.parentNode.insertBefore(js, fjs);return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });}(document, \"script\", \"twitter-wjs\"));(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return;js = d.createElement(s); js.id = id; js.src = \"//connect.facebook.net/en_GB/all.js#xfbml=1\"; fjs.parentNode.insertBefore(js, fjs);}(document, \"script\", \"facebook-jssdk\"));var script_generated=1";
           // use this for inline script
  document.body.appendChild(script);
} 

Doing this script tag is not regenerated but the tweet and Facebook like buttons still don’t show up.

Now what I have interpreted (I might be wrong) that as the script tags are generated by ajax request the buttons are not properly displayed as they don’t find their script tags.

Now what I want is that whenever a request is sent to that file, it first checks whether that particular script tag exists, deletes that if it exists and generate a new one, else generate. Please guide me how to do this.

If I have interpreted the problem wrong, then please let me know what is the exact problem and how to overcome this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:01:27+00:00Added an answer on June 4, 2026 at 1:01 pm

    Well you can give id to script tag when you are adding dynamically.

    var script   = document.createElement("script");
    script.setAttribute('id', 'addedScript');
    script.type  = "text/javascript";
    script.text  = "window.twttr = (function (d,s,id) {var t, js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;js.src=\"//platform.twitter.com/widgets.js\"; fjs.parentNode.insertBefore(js, fjs);return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });}(document, \"script\", \"twitter-wjs\"));(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return;js = d.createElement(s); js.id = id; js.src = \"//connect.facebook.net/en_GB/all.js#xfbml=1\"; fjs.parentNode.insertBefore(js, fjs);}(document, \"script\", \"facebook-jssdk\"));var script_generated=1";
    // use this for inline script
    document.body.appendChild(script);
    

    After that you can check if script tag exists by using this and remove using .remove() query function.

    if(addedScript != undefined) {
      $("#addedScript").remove();
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im facing a problem. I have a listing page in which i list all
I am facing a critical problem i am using ajaxmodalpopupextender in my page. It's
I facing very huge problem now, that is I have usercontrol (created by me)
Am facing a problem, while creating components through TOM API using .NET/COM Interop. Actual
Im facing following problem I have created mentioned condition, but when I choose y
I am facing an issue that is driving me insane. I have one and
im facing a problem where i need some advice. I want to have a
Context: An ongoing problem we have been facing is unit testing our market data
I am facing one critical issue in SQL Azure database, i have created this
I facing a problem regarding the import of an excel file into mysql through

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.