Alberto Rossi
Alberto Rossi

Reputation: 1800

Javascript changing iframe src doesn't work

On my website I wrote a function like this:

function apri(dat) {
document.getElementId('dado').src= dat;
}

and the iframe HTML code is the following.

<iframe id="dado"src="http://mk7vrlist.altervista.org/" width="100%" height="700px" scrolling="yes" frameBorder="0">
  Your browser doesn't load this iframe.
</iframe>

I call the apri() function in this way:

<p onclick="apri(http://mk7vrlist.altervista.org/other/staffpage.html)"> <img src="/pictures/uno.png" /> Staffers</p>

The content of my iframe is not changing. I've googled this a lot but I didn't find any solution. What can I do?

Do you think I should use something different instead of the iframe?

Upvotes: 0

Views: 686

Answers (1)

epascarello
epascarello

Reputation: 207557

Check your error console after you click the text. You will see an error message.

SyntaxError: missing ) after argument list

The bug is quoting problem. You have a string with no quotes around it.

<p onclick="apri('http://mk7vrlist.altervista.org/other/staffpage.html')">
                 ^                                                    ^
              missing                                               missing

Upvotes: 4

Related Questions