0

I'm trying to create a chrome extension that allows two URL's to be inputted into one tab. I break it up with framesetinto left and right. Here's the code:

Background.html

<!DOCTYPE html>
<html>     
    <head>     
        <title>A frame with two pages</title>    
    </head>
    <frameset cols="*,*">
        <frame src="left.html" name="left">
        <frame src="right.html" name="right">     
    </frameset>     
</html>

Left and Right

<!DOCTYPE html>
<html>
<body onLoad="document.getElementById('urlToJump').value='http://www.foxnews.com/'">     
    <div class="menu">           
        <form>     
            <br>
            <input type="text" id="urlToJump">
            <br>     
            // Test 1 (custom input)
            <input type="button" id="restore" value="Go to the URL above" onclick="window.location.href=document.getElementById('urlToJump').value;" />     
            <br> 
            // Test 2 (calling function)
            <input type="button" value="Load new document" onclick="newDoc()">   
        </form>
    </div>
    <script>
        function newDoc() {
            window.location.assign("http://www.w3schools.com")
        }
    </script>
</body>     
</html>

Both tests didn't work, as neither loaded the intended target. How can this be resolved? I'm trying to recreate the Chrome extension found here, and add more to it. Thanks!

Kragalon
  • 390
  • 1
  • 2
  • 25

1 Answers1

1

The problem here is that Chrome extensions don't allow you to have inline JavaScript, which really sucks. The solution would be to give your button an ID, then use jQuery or JavaScript to select your button and give it the onclick property in the JavaScript file.

  • So I just need a separate JS file? I've inspected extensions where this was possible, if I recall correctly. – Kragalon Feb 15 '16 at 03:23
  • Yes by convention, but the problem is that you can't pass the onclick property inline. You need to pass that in the actual JavaScript code, at least I have had to in the past. You can find more information on this post: https://developer.chrome.com/extensions/contentSecurityPolicy#JSExecution – Garrett Stewart Feb 15 '16 at 03:25
  • @Kragalon They may be ancient extensions using manifest version 1. Currently you cannot develop new extensions that use the old conventions. – Xan Feb 15 '16 at 14:34
  • Yep. Xan is right. Thank you and I hope I could help. At the time, I wasn't aware of inline JavaScript support in MV1 – Garrett Stewart Feb 15 '16 at 18:40