I am trying to create an extension for Safari browser that will add a bar(.html) with a listbox of several links and a button. When I click on the button the selected item (e.g. link) from the listbox will open in a new tab.
If item Microsoft is selected and user click on button Open it will open www.microsoft.com in a new tab.
I have tried with the two functions selectedLink below, but neither seems to work. I might be doing it wrong though.
The other function openInTab is needed since I am working with a Safari extension, in case someone wonders why I am not using window.open.
<html>
<head>
<title>Links</title>
<select id="selectbox" name="" onchange="selectedLink(this);" ;>
<option value="https://www.google.com" selected>Google</option>
<option value="https://www.microsoft.com">Microsoft</option>
<option value="https://www.apple.com">Apple</option>
</select>
<button onclick="openInTab(pSelect);">Open</button>
<script type="text/javascript">
function selectedLink(getLink) {
var pSelect = getLink.value;
}
function selectedLink(getLink) {
var selectIndex = getLink.selectedIndex;
var selectValue = getLink.options[selectIndex].text;
var pSelect = selectValue;
}
function openInTab(source) {
var newTab = safari.self.browserWindow.openTab();
newTab.url = source;
}
</script>
</head>
</html>
Returns:
ReferenceError: Can't find variable: pSelect