Add a parameter to the query string of all URLs loaded in WKWebView

I use the "new" WKWebView to view the site in it, for example http://mywebsite.com .

I would make sure that the application will pass an additional parameter to each loaded page, for example: http://mywebsite.com/?username=foo .

Obviously I have no problem for the first page. In Swift:

 let url = NSURL(string: "http://mywebsite.com/?username=foo")! let urlRequest = NSURLRequest(URL: url) webView.loadRequest(urlRequest) 

But if there is a link on the http://mywebsite.com homepage, say http://mywebsite.com/page.php?id=5 , how can I intercept it to add the username=foo parameter? I'm sorry this was an open page http://mywebsite.com/page.php?id=5&username=foo .

+5
source share

Source: https://habr.com/ru/post/1235141/


All Articles