button click: open a new browser tab and call a function


fiber

I have a button which calls a function:

  • Perform an AJAX PHP request to the database

  • Display the retrieved data in a div container

  • scroll to div container with bookmark (#)

I want a button to do the same task, but with one action, which is to open a new tab and scroll to the div. Therefore it must:

  • Open a new tab
  • Call the function that executes the request
  • Display the retrieved data in a div container
  • scroll to div container with bookmark (#)

How can I achieve this?

tom

I recommend using query strings . After retrieving the data in the AJAX callback, urlencode it and append it to the route's link.

$.ajax({
    url : 'example.com',
    type: 'GET',
    success : (response) => {
        window.open(
            'http://example.com/my-target-route' + '?content=' + encodeURIComponent(response.data) + '#my-div-container',
            '',
            ''
        )
    }
})

On the target page, parse the query parameters as follows:

let urlParams = new URLSearchParams(window.location.search);
let myDiv = document.querySelector('#my-div-container');

myDiv.innerHTML = urlParams.get('content');

Alternatively, you can try running the method from a new tab stored locally .

Related


button click: open a new browser tab and call a function

fiber I have a button which calls a function: Perform an AJAX PHP request to the database Display the retrieved data in a div container scroll to div container with bookmark (#) I want a button to do the same task, but with one action, which is to open a new t

Click the button to open a new tab

Nathan Wilson I want to create a link with a button that opens in a new tab. The code I'm currently using is currently opening a blank tab and I'm not sure why. <div class="text text-left"> <h2>WORK</h2> <h1>Title</h1> <p>Lorem ipsum dolor sit am

Click the button to open a new tab

Nathan Wilson I want to create a link with a button that opens in a new tab. The code I'm currently using is currently opening a blank tab and I'm not sure why. <div class="text text-left"> <h2>WORK</h2> <h1>Title</h1> <p>Lorem ipsum dolor sit am

Open a new browser tab by clicking a button in Javascript

Chris Lall 123 I am trying to write a javascript function behind a button so that when I press the button it will open a new tab and call the report_handler to open the report. My current code behind that button is; <dx:ASPxButton ID="btn_Print" runat="server"

Open a new browser tab by clicking a button in Javascript

Chris Lall 123 I am trying to write a javascript function behind a button so that when I press the button it will open a new tab and call the report_handler to open the report. My current code behind that button is; <dx:ASPxButton ID="btn_Print" runat="server"

Open a new tab after button click in AngularJS

Neptune: <button type="button" class="btn btn-primary" ng-click="openTab()">new tab</button> openTab = function () { $http.post('www.google.com'); } What I want is to post a requirement and then open the response html in a new tab when the "openTab" button

Protractor button click and open page in new tab

Sumitomo I am new to protractor. I'm trying to automate a scenario where I click a button and it opens a page in a new tab and then we need to populate the form in the new page and submit it. Problem : When I click the button to open a new page. My tests don't

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Protractor button click and open page in new tab

Sumitomo I am new to protractor. I'm trying to automate a scenario where I click a button and it opens a page in a new tab and then we need to populate the form in the new page and submit it. Problem : When I click the button to open a new page. My tests don't

Open a new tab after button click in AngularJS

Neptune: <button type="button" class="btn btn-primary" ng-click="openTab()">new tab</button> openTab = function () { $http.post('www.google.com'); } What I want is to post a requirement and then open the response html in a new tab when the "openTab" button

Open new tab on button click using JQUERY

Rajan My scene is like this: I have edit user module. Each user is assigned a base INI file . When we edit a user, we have a drop down menu from which to select his base INI file. After selection, we can save the user. And the ID of the selected file is also s

Protractor button click and open page in new tab

Sumitomo I am new to protractor. I'm trying to automate a scenario where I click a button and it opens a page in a new tab and then we need to populate the form in the new page and submit it. Problem : When I click the button to open a new page. My tests don't

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Open new tab on button click using JQUERY

Rajan My scheme is this: I have edit user module. Each user is assigned a base INI file . When we edit a user, we have a drop down menu from which to select his base INI file. After selection, we can save the user. And the ID of the selected file is also saved

Protractor button click and open page in new tab

Sumitomo I am new to protractor. I'm trying to automate a scenario where I click a button and it opens a page in a new tab and then we need to populate the form in the new page and submit it. Problem : When I click the button to open a new page. My tests don't

Open a new tab after button click in AngularJS

Neptune: <button type="button" class="btn btn-primary" ng-click="openTab()">new tab</button> openTab = function () { $http.post('www.google.com'); } What I want is to post a requirement and then open the response html in a new tab when the "openTab" button

Protractor button click and open page in new tab

Sumitomo I am new to protractor. I'm trying to automate a scenario where I click a button and it opens a page in a new tab and then we need to populate the form in the new page and submit it. Problem : When I click the button to open a new page. My tests don't

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Open new tab on button click using JQUERY

Rajan My scheme is this: I have edit user module. Each user is assigned a base INI file . When we edit a user, we have a drop down menu from which to select his base INI file. After selection, we can save the user. And the ID of the selected file is also saved

Open a new browser tab

heal me I have tried several functions but none seem to work? E.g: element, _ := webdriver.FindElement(selenium.ByCSSSelector, "body") element.SendKeys(selenium.ControlKey + "t") Richard Edwards Selenium is able to execute javascript in the browser. To open a

Open a new browser tab

heal me I have tried several functions but none seem to work? E.g: element, _ := webdriver.FindElement(selenium.ByCSSSelector, "body") element.SendKeys(selenium.ControlKey + "t") Richard Edwards Selenium is able to execute javascript in the browser. To open a

How to open new window browser when user click close tab?

end I tried this code to open new window browser when user click close tab but it doesn't work <script> window.onbeforeunload = function(e) { window.open("http://google.com"); window.stop(); }; </script> So, can you give me any way to do this? Quentin y

How to open new window browser when user click close tab?

end I tried this code to open new window browser when user click close tab but it doesn't work <script> window.onbeforeunload = function(e) { window.open("http://google.com"); window.stop(); }; </script> So, can you give me any way to do this? Quentin y

Open URL in new browser tab when HTML button is clicked

Yousef Rahimy Akhondzadeh I'm designing a website using CodeIgniter and I want to open some URLs when the user clicks a button (the URL must open in a new tab). I use this code and it works when you want to open the URL in the same tab, but I want the URL to o

Alert on button click and move user to open new tab

Dashan I created a button with a link that opens in a new tab. I also used JavaScript for reminders. Currently this code works fine. But after clicking OK in the Alert, the user stays on the same page. But I want to move the user to the newly opened tab. is it

Alert on button click and move user to open new tab

Dashan I created a button with a link that opens in a new tab. I also used JavaScript for reminders. Currently this code works fine. But after clicking OK in the Alert, the user stays on the same page. But I want to move the user to the newly opened tab. is it