Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging attr value with Jquery
    primarykey
    data
    text
    <p>I am trying to change out a src value of an Iframe when a link is clicked and change out the value with the href from it. When the button is clicked, I prevent the default action, and replace the src value with the url. The code works for values that are not urls, causing the iframe to display a page not found, but does not work when a valid url is provided. Here is the code for the pages in use.</p> <p>This is the main script I have been using to run the site</p> <pre><code>$.ajaxSetup ({ cache: false }); $(document).ready(function(){ $('.pageContent').load('home.php'); setInterval("changePage()",250); }); function changePage(hash) { $('.youtubeLink').click(function(e) { e.preventDefault(); var temp = $(this).attr("href"); //alert (temp); $('#youtubePlayerFrame').attr('src', temp); //when using var temp no action occurs //when testing temp, it does hold the url, if i replace temp with a string such as //'asdasd' the script works correctly but replaces the frame with a 404 error }) $(window).hashchange( function(){ if(!hash) hash=window.location.hash; hash = hash.replace('#',''); if (hash =='') { $('.pageContent').load('home.php'); } } else { $('.pageContent').load( hash + '.php'); hash = null; } }) } </code></pre> <p>This code is the main div that holds the youtube player</p> <pre><code>&lt;?php echo ' &lt;div class="youtubePlayer" &gt; &lt;iframe width="420" height="315" id = "youtubePlayerFrame" src="http://www.youtube.com/embed/j8Szl_JyCUQ" frameborder="0" allowfullscreen style="margin-top:34px; margin-left:20px;"&gt;&lt;/iframe&gt; &lt;/div&gt; '; include 'sideDirectory.php'; include 'sideMenu.php'; ?&gt; </code></pre> <p>This last code is the php file for the directory with the links</p> <pre><code>&lt;?php echo' &lt;div class="sideDirectory"&gt; &lt;table&gt;&lt;tbody&gt; '; $file = fopen("../data/recentlyAdded.txt","r"); $linksFile = fopen("../data/links.txt","r"); while($line =fgets($file)) { $url = fgets($linksFile); // echo '&lt;tr&gt;&lt;td&gt;' .$url. '&lt;/td&gt;&lt;/tr&gt;'; echo '&lt;tr&gt;&lt;td&gt;&lt;a class="youtubeLink" href="'.$url.'"&gt;'.$line.'&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;'; } fclose($file); fclose($linksFile); echo ' &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; '; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload