Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:17:19+00:00 2026-06-15T19:17:19+00:00

I have this javascript code: function handleCommand (event) { if (event.command === ‘send’) {

  • 0

I have this javascript code:

function handleCommand (event) {
    if (event.command === 'send') {
        sendingLink(event.target.browserWindow.activeTab.url);
    } else if (event.command === 'sendMenu') {
        sendingLink(safari.application.activeBrowserWindow.activeTab.url);
    }
};

I want to be able to make an “if” statement where I: 1) grab the id “leurl” if the link is “https://maps.google.com/, and 2) if it’s not a Google Map link, then grab the link from the address bar. I got the second part, but I don’t know how to do the first one. I know how to do it when making a Google Chrome extension though (document.getElementById('link');).

How would I be able to accomplish this? Any help is appreciated. Thank you in advance.

Please forgive me as I am not too familiar at making Safari extensions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:17:20+00:00Added an answer on June 15, 2026 at 7:17 pm

    If I understand correctly, you want to get some information contained on the current page into your global page. Unfortunately using document.getElementById('link'); won’t work directly, as the global page doesn’t have access to the content of web pages (for security reasons, I think).

    You will have to use an injected script, and messaging to send the information to the global page. For example, you might do the following:

    global.js

    const app = safari.application;
    app.addEventListener('message', handleMessage, false);
    
    function sendingLink(link) {
        app.activeBrowserWindow.activeTab.page.dispatchMessage('getLink');
    }
    
    function handleMessage(msg) {
        if (msg.name === 'returnLink') {
            alert(msg.message);
        }
    }
    

    injected.js

    safari.self.addEventListener('message', handleMessage, false);
    
    function handleMessage(msg) {
        if (msg.name === 'getLink') {
            // Trigger share button. Maybe:
            // document.getElementById('link').click();
            var link = document.getElementById('leurl').value;
            safari.self.tab.dispatchMessage('returnLink', link);
        }
    }
    

    Then make sure these are set as the global page and an injected script respectively, in the Safari Extension Builder.

    The Apple Safari Extensions Development Guide is a great resource for things like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: $(#menu).on('click', 'a', function (event) { javascript code ... }); $(#home).on('click',
I have this javascript code <Script> function getGroupId(){ var group=document.getElementById(selectedOptions).value; var groupFirstLetter=group.substring(2); } </Script>
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
As you may know, when we have this code in Javascript : function getName()
Ok, I have this code: <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script> <script type=text/javascript> function get()
I have this follow code in my javascript. I call this function when the
I have the following Javascript code add_num = { f: function(html, num) { alert(this.page);
I have this code: <script type=text/javascript> var maxLength=10; function charLimit(el) { if (el.value.length >
I have this code running great in ff, opera and chrome: <script type=text/javascript> $(document).ready(function(){
I have this simple code that speaks for itself. <script language='javascript"> function check() {}

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.