0

I am trying to call openswf function when i click on SWF part1 links which is in document.write(), but my problem is when i clicked on SWF part1 links it nothing happen.

This is my code.

<html>
    <a href="#" onclick="Popup();">show popup</a>

<script>
    function openswf(){
        console.log("Do something")

    }
    function Popup()
    {
        var win = window.open('', '',"toolbar=no, width=1000, height=800");
        var doc = win.document.open();
        doc.write('<a href="javascript:openswf();">SWF part1</a>');
        doc.close();
    }

</script>
</html>

First i click on show popup links to call Popup() function and open new popup window which is work properly and then i want to click on SWF part1 links in that popup but it not working.

3
  • What is path, where does it get a value? Commented Feb 2, 2020 at 13:33
  • @trincot This is just a demo code, for now i just want to click on links and call openswf() function. Commented Feb 2, 2020 at 13:35
  • OK, but it is better to remove path then from your question. As it is, it will produce an error. Better make sure your code is fine, except for the issue you address. Commented Feb 2, 2020 at 13:38

3 Answers 3

4

openswf is not defined in the popup window, but in the main window. But you can reference the main window with opener. I suppose you want to close the popup window when the user clicks:

doc.write('<a href="javascript:opener.openswf();close();">SWF part1</a>');
Sign up to request clarification or add additional context in comments.

2 Comments

may i ask more question how can i pass variable with openswf() because i try with this code doc.write('<a href="javascript:opener.openswf('+path+');">SWF part1</a><br>'); but it error like this missing ) after argument list
i got the answer now, i try with this code doc.write('<a href="javascript:opener.openswf(\''+path+'\');">SWF part1</a><br>'); thank you for help :)
0

It's probably calling the default <a> onClick event. You have to preventDefault().


function Popup(event) 
{
   event.preventDefault();
   var win = window.open('', '',"toolbar=no, width=1000, height=800");
   var doc = win.document.open();
   doc.write('<a href="javascript:openswf(path);">SWF part1</a>');
   doc.close();

}

Let me know if it helps.

1 Comment

thank you for response, i'm try with that but it still not working, it error like this "ReferenceError: openswf is not defined"
-2

For starters, the variable "path" is not being passed to your new window. Use this instead...

function Popup(path)
{
    var win = window.open('', '',"toolbar=no, width=1000, height=800");
    var doc = win.document.open();
    doc.write('<a href="javascript:openswf('+path+');">SWF part1</a>');
    doc.close();
}

2 Comments

That is not going to work, even if path is defined.
@user4723924 i'm sorry, actually this is just a demo code, but what i want is click on links and do the openswf(), now i have edit my code in the question and i have got the answer, thank you for response :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.